// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Enums/EItemState.h"

#include "Item.generated.h"

class USphereComponent;

UCLASS()
class RPG_API AItem : public AActor
{
	GENERATED_BODY()
	
public:	
	// 构造函数
	AItem();
	// 每帧运行
	virtual void Tick(float DeltaTime) override;
protected:
	// 开始运行
	virtual void BeginPlay() override;
	
	UFUNCTION(BlueprintPure)
	float F_Sin() const;
	
	UFUNCTION(BlueprintPure)
	float F_Cos() const;

	template <typename T>
	T Avg(T First, T Second);

	// 重叠委托回调函数
	UFUNCTION()
	virtual void F_OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
	                               int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
	// 重叠结束委托回调函数
	UFUNCTION()
	virtual void F_OnSphereEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
	                                  UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

	// 物体上下浮动函数
	UFUNCTION()
	virtual void F_Float();
	
	// 物品网格体组件
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
	UStaticMeshComponent* ItemMesh;

	// 球体组件
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
	USphereComponent* SphereComp;

	//是否浮动?
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Enum")
	EItemState ItemState = EItemState::EIS_Static;	

private:
	UPROPERTY(VisibleAnywhere,BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	float RunningTime = 0.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sine Parameters", meta = (AllowPrivateAccess = "true"))
	float Amplitude = 10.f;	//振幅
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sine Parameters", meta = (AllowPrivateAccess = "true"))
	float TimeConstant = 5.f;	//时间常数

};


template <typename T>
inline T AItem::Avg(T First, T Second)
{
	return ((First + Second )/ 2);
}